class ContactService {

  static expose = ['flex-remoting']

  boolean transactional = true

  def getContacts() {
    return Contact.list()
  }

  def get(id) {
    return Contact.get(id)
  }

  def update(Contact contact) {
    contact.save()
    publishContacts()
  }

  def remove(Contact contact) {
    contact.delete(flush: true)
    publishContacts()
  }

  def private void publishContacts() {
    try {
      sendPubSubJMSMessage("contacts", getContacts());
    } catch (Exception e) {
      log.error("Failed to publish contacts.", e);
    }
  }


}
